#include "Point3D.h"
#include "Direction3D.h"
#include "../GameLib.h"
#include <math.h>
#include "../../OpenGL.h"
#include "../Str.h"
#include "Vector3D.h"

Point3D::Point3D(){x=0.0;y=0.0;}
Point3D::Point3D(double x,double y,double z){
    this->x=x;
    this->y=y;
    this->z=z;
}
Point3D::~Point3D(){}
Point3D&	Point3D::set(double x,double y,double z){
    this->x=x;
    this->y=y;
    this->z=z;
    return *this;
}
double		Point3D::getX(){return x;}
double		Point3D::getY(){return y;}
double		Point3D::getZ(){return z;}
Point3D&	Point3D::setX(double x){this->x=x;return *this;}
Point3D&	Point3D::setX(Point3D &pt){x=pt.getX();return *this;}
Point3D&	Point3D::setY(double y){this->y=y;return *this;}
Point3D&	Point3D::setY(Point3D &pt){y=pt.getY();return *this;}
Point3D&	Point3D::setZ(double z){z=z;return *this;}
Point3D&	Point3D::setZ(Point3D &pt){z=pt.getZ();return *this;}
double		Point3D::distance(Point3D &pt){
    return sqrt(pow(x-pt.getX(),2.0)+pow(y-pt.getY(),2.0)+pow(z-pt.getZ(),2.0));
}
Point3D&	Point3D::direction(Point3D &pt, Direction3D &dir){
    dir.setFromLength(pt.getX()-x, pt.getY()-y, pt.getZ()-z);
    return *this;
}
Point3D&	Point3D::copy(Point3D &pt){
    x=pt.getX();
    y=pt.getY();
    z=pt.getZ();
    return *this;
}
Point3D&	Point3D::add(Point3D &pt){
    x+=pt.getX();
    y+=pt.getY();
    z+=pt.getZ();
    return *this;
}
Point3D&	Point3D::add(Vector3D &v){
	x+=v.getX();
	y+=v.getY();
	z+=v.getZ();
	return *this;
}
Point3D&	Point3D::sub(Point3D &pt){
    x-=pt.getX();
    y-=pt.getY();
    z-=pt.getZ();
    return *this;
}
Point3D&	Point3D::sub(Vector3D &v){
	x-=v.getX();
	y-=v.getY();
	z-=v.getZ();
	return *this;
}
Point3D&	Point3D::move(Direction3D &dir, double distance){
    x+=dir.getI()*distance;
    y+=dir.getJ()*distance;
    z+=dir.getK()*distance;
    return *this;
}
bool		Point3D::isEq(Point3D &pt){
    return (x==pt.getX()&&y==pt.getY()&&z==pt.getZ())?true:false;
}
bool		Point3D::isNeq(Point3D &pt){return !isEq(pt);}
Point3D&	Point3D::operator+=(Point3D &pt){return add(pt);}
Point3D&	Point3D::operator+=(Vector3D &v){return add(v);}
Point3D&	Point3D::operator-=(Point3D &pt){return sub(pt);}
Point3D&	Point3D::operator-=(Vector3D &v){return sub(v);}
Point3D&	Point3D::operator=(Point3D &pt){return copy(pt);}
bool		Point3D::operator==(Point3D &pt){return isEq(pt);}
bool		Point3D::operator!=(Point3D &pt){return isNeq(pt);}
Str			Point3D::toString(){
	Str temp;
    temp<<"("<<x<<", "<<y<<", "<<z<<")";
    return temp;
}
void		Point3D::useAsVertex(){
    glVertex3f((float)x, (float)y, (float)z);
}
void		Point3D::draw(){
    glBegin(GL_POINTS);
    useAsVertex();
    glEnd();
}
void		Point3D::draw_color(int hexColor){
    float c[4];
    gameLib.getColorA(c);
    gameLib.setColor(hexColor);
    draw();
    gameLib.setColorA(c);
}
void		Point3D::draw_size(double radius){
    gameLib.setPointSize(radius);
    draw();
}
void		Point3D::draw_sizeColor(double radius, int hexColor){
    gameLib.setPointSize(radius);
    draw_color(hexColor);
}
